package com.example.perftool2;

import android.content.pm.ApplicationInfo;
import android.net.TrafficStats;

public class AppInfo {

    private String name;
    private String pkgName;
    private int uid;
    private int pid;
    private String powerConsume;
    private long mRx;
    private long mTx;
    // meminfo 单位是B
    private long mMem;
    // top的，百分比
    private String mMemPercent;
    private String dumpsysCpuUsage = "no_init";
    private String shCpuUsage = "no_init";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getUid() {
        return uid;
    }

    public void setUid(int uid) {
        this.uid = uid;
    }

    public String getPkgName() {
        return pkgName;
    }

    public void setPkgName(String pkgName) {
        this.pkgName = pkgName;
    }

    public String getRxString() {
        return Tool.byteToMB(mRx);
    }

    public String getTxString() {
        return Tool.byteToMB(mTx);
    }

    public String getPowerConsume() {
        return powerConsume;
    }

    public void setPowerConsume(String powerConsume) {
        this.powerConsume = powerConsume;
    }

    public int getPid() {
        return pid;
    }

    public void setPid(int pid) {
        this.pid = pid;
    }

    public long getMem() {
        return mMem;
    }

    public String getMemString() {
        return Tool.byteToMB(mMem);
    }

    public void setMem(long mMem) {
        this.mMem = mMem;
    }

    public String getDumpsysCpuUsage() {
        return dumpsysCpuUsage;
    }

    public void setDumpsysCpuUsage(String dumpsysCpuUsage) {
        this.dumpsysCpuUsage = dumpsysCpuUsage;
    }

    public String getShCpuUsage() {
        return shCpuUsage;
    }

    public void setShCpuUsage(String shCpuUsage) {
        this.shCpuUsage = shCpuUsage;
    }

    public void updateNetworkDate() {
        mRx = getRxBytes(getUid());
        mTx = getTxBytes(getUid());
    }

    public AppInfo() {
    }

    private long getRxBytes(int uid){
        return TrafficStats.getUidRxBytes(uid);
    }

    private long getTxBytes(int uid){
        return TrafficStats.getUidTxBytes(uid);
    }

    public String getMemPercent() {
        return mMemPercent;
    }

    public void setMemPercent(String mMemPercent) {
        this.mMemPercent = mMemPercent;
    }

    @Override
    public String toString() {
        return "AppInfo{" +
                "name='" + name + '\'' +
                ", pid=" + pid +
                ", mMem=" + Tool.byteToMB(mMem) +
                ", mMemPercent=" + mMemPercent + "%" +
                ", shCpuUsage=" + shCpuUsage +
                ", cpuUsage=" + dumpsysCpuUsage +
                ", powerConsume='" + powerConsume + '\'' +
                ", download=" + Tool.byteToMB(mRx) +
                ", upload=" + Tool.byteToMB(mTx) +
                '}';
    }
}
